package com.servlet.project.service;

import com.servlet.project.entity.Announcement;
import com.servlet.project.entity.Member;
import com.servlet.project.util.JdbcUtil;

import java.util.List;

public class AnnouncementService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into announcement(announcementtitle,announcementcontent,announcementdate,announcementpublisher) values(?,?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<Announcement> getListAll(int page, int rows, Announcement obj) {
        String sql="select * from announcement where 1=1 ";
        if(obj.getAnnouncementtitle()!=null&&!obj.getAnnouncementtitle().equals("")){
            sql+=" and announcementtitle like '%"+obj.getAnnouncementtitle()+"%' ";
        }
        sql+=" limit "+page+","+rows;
        List<Announcement> memberList= JdbcUtil.executeQuery(sql,null,Announcement.class);
        return memberList;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(Announcement obj) {
        String sql="select * from announcement where 1=1 ";
        if(obj.getAnnouncementtitle()!=null&&!obj.getAnnouncementtitle().equals("")){
            sql+=" and announcementtitle like '%"+obj.getAnnouncementtitle()+"%' ";
        }
        List<Announcement> memberList= JdbcUtil.executeQuery(sql,null,Announcement.class);
        return memberList.size();
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update announcement set announcementtitle=?,announcementcontent=?,announcementdate=?,announcementpublisher=? where announcementid=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param announcementid
     * @return
     */
    public Announcement getId(String announcementid) {
        String sql="select * from announcement where announcementid="+announcementid;
        List<Announcement> users= JdbcUtil.executeQuery(sql,null,Announcement.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from Announcement  where announcementid=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
